package hw02;

import hw01.Answers;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class Meta {

	public static Map<String, Method> methods = new HashMap<String, Method>();
	public static List<String> orderedMethods = new LinkedList<String>();
	public static Map<String, List<String>> methodInput = new HashMap<String, List<String>>();
	public static Map<String, List<String>> methodOutput = new HashMap<String, List<String>>();
	public static Map<String, Map<String, String>> linkedParams = new HashMap<String, Map<String,String>>();
	
	static {
		List<String> paramNames = new LinkedList<String>();
		paramNames.add("user");
		paramNames.add("password");
		methodInput.put("connect", paramNames);
		paramNames = new LinkedList<String>();
		methodOutput.put("connect", paramNames);
		orderedMethods.add("connect");

		paramNames = new LinkedList<String>();
		methodInput.put("createTables", paramNames);
		paramNames = new LinkedList<String>();
		methodOutput.put("createTables", paramNames);
		orderedMethods.add("createTables");

		paramNames = new LinkedList<String>();
		methodInput.put("destroyTables", paramNames);
		paramNames = new LinkedList<String>();
		methodOutput.put("destroyTables", paramNames);
		orderedMethods.add("destroyTables");

		paramNames = new LinkedList<String>();
		paramNames.add("building");
		paramNames.add("floor");
		paramNames.add("room number");
		paramNames.add("directions");
		methodInput.put("addRoom", paramNames);
		paramNames = new LinkedList<String>();
		paramNames.add("room identifier");
		methodOutput.put("addRoom", paramNames);
		orderedMethods.add("addRoom");

		paramNames = new LinkedList<String>();
		paramNames.add("room substring");
		methodInput.put("findRoom", paramNames);
		paramNames = new LinkedList<String>();
		paramNames.add("room identifier");
		paramNames.add("building name");
		paramNames.add("room number");
		methodOutput.put("findRoom", paramNames);
		orderedMethods.add("findRoom");
		
		paramNames = new LinkedList<String>();
		paramNames.add("room identifier");
		methodInput.put("describeRoom", paramNames);
		paramNames = new LinkedList<String>();
		paramNames.add("building name");
		paramNames.add("room number");
		paramNames.add("floor");
		paramNames.add("number of chairs");
		paramNames.add("number of screens");
		methodOutput.put("describeRoom", paramNames);
		orderedMethods.add("describeRoom");
		
		paramNames = new LinkedList<String>();
		paramNames.add("building");
		paramNames.add("room number");
		paramNames.add("number of chairs");
		paramNames.add("number of screens");
		paramNames.add("comments");
		methodInput.put("addFacilities", paramNames);
		paramNames = new LinkedList<String>();
		paramNames.add("facility identifier");
		methodOutput.put("addFacilities", paramNames);
		orderedMethods.add("addFacilities");
		
		paramNames = new LinkedList<String>();
		paramNames.add("start time");
		paramNames.add("end time");
		paramNames.add("building name");
		paramNames.add("room number");
		paramNames.add("holder's name");
		methodInput.put("addReservation", paramNames);
		paramNames = new LinkedList<String>();
		paramNames.add("confirmation number");
		methodOutput.put("addReservation", paramNames);
		orderedMethods.add("addReservation");
		
		paramNames = new LinkedList<String>();
		paramNames.add("confirmation number");
		methodInput.put("describeReservation", paramNames);
		paramNames = new LinkedList<String>();
		paramNames.add("building name");
		paramNames.add("room number");
		paramNames.add("start time");
		paramNames.add("end time");
		paramNames.add("holder's name");
		methodOutput.put("describeReservation", paramNames);
		orderedMethods.add("describeReservation");
		
		paramNames = new LinkedList<String>();
		paramNames.add("cron pattern");
		paramNames.add("reservation length (in minutes)");
		paramNames.add("building name");
		paramNames.add("room number");
		paramNames.add("holder's name");
		methodInput.put("makeReservations", paramNames);
		paramNames = new LinkedList<String>();
		paramNames.add("confirmation number");
		methodOutput.put("makeReservations", paramNames);
		orderedMethods.add("makeReservations");
		
		paramNames = new LinkedList<String>();
		paramNames.add("cron pattern");
		paramNames.add("building name");
		paramNames.add("room number");
		methodInput.put("matchReservation", paramNames);
		paramNames = new LinkedList<String>();
		paramNames.add("confirmation number");
		methodOutput.put("matchReservation", paramNames);
		orderedMethods.add("matchReservation");
		
		paramNames = new LinkedList<String>();
		paramNames.add("cron pattern");
		paramNames.add("reservation length (in minutes)");
		paramNames.add("number of chairs");
		paramNames.add("number of screens");
		methodInput.put("getFreeRoom", paramNames);
		paramNames = new LinkedList<String>();
		paramNames.add("building name");
		paramNames.add("room number");
		methodOutput.put("getFreeRoom", paramNames);
		orderedMethods.add("getFreeRoom");
		
		for(Method method : Answers.class.getDeclaredMethods()) {
			methods.put(method.getName(), method);
		}
		
		Map<String, String> paramHref = new HashMap<String, String>();
		paramHref.put("q", ResultPage.class.getName());
		paramHref.put("function", "describeRoom");
		linkedParams.put("room identifier", paramHref);

		paramHref = new HashMap<String, String>();
		paramHref.put("q", ResultPage.class.getName());
		paramHref.put("function", "describeReservation");
		linkedParams.put("confirmation number", paramHref);
	}

}
